/**
 * Created by Administrator on 2017/12/11.
 */
import React, {PureComponent} from 'react';
import styles from './index.less';
import { routerRedux } from 'dva/router';
import {Link} from 'dva/router';
import {connect} from 'dva';
import {message} from "antd/lib/index";
import {powerControl} from '../../utils/powerControl';
import {Table,Button,Rate ,Alert, Badge, Switch, Icon, InputNumber, Tooltip, Popconfirm}  from 'antd';
import constants from '../../common/constants';
import list from "../../models/list";
import global from "../../models/global";
import OrderManage from "../../models/orderManage";
;
const getValue = obj => Object.keys(obj).map(key => obj[key]).join(',');
const AuthButton = powerControl(Button);

@connect(state => ({
    orderManage:state.orderManage,
}))
export default class OrderManageTable extends PureComponent{



    handleUpdateConfirm = (order_id,pagination,formValues ) => {
        const params = {
            currentPage: pagination.current,
            pageSize: pagination.pageSize,
            ...formValues,
        };

            this.props.dispatch({
                type: 'orderManage/modConfirm',
                payload: {order_id: order_id},

                callback: (response) => {
                    if (response.result === 0) {
                        message.success('提交成功');
                        const {dispatch} = this.props;
                        // this.handleModalVisible(true);
                        dispatch({
                            type: 'orderManage/fetch',
                            payload:params,
                        });

                    } else {
                        message.success('提交失败');
                    }
                }
        });
    }

    handleUpdatePay = (order_id,pagination,formValues ) => {
        const params = {
            currentPage: pagination.current,
            pageSize: pagination.pageSize,
            ...formValues,
        };
        this.props.dispatch({
            type: 'orderManage/modPay',
            payload: {order_id: order_id},
            callback: (response) => {
                if (response.result === 0) {
                    message.success('提交成功');
                    const {dispatch} = this.props;
                    // this.handleModalVisible(true);
                    dispatch({
                        type: 'orderManage/fetch',
                        payload:params
                    });

                } else {
                    message.success('提交失败');
                }
            }
        });
    }

    handleUpdateShipping = (order_id,pagination,formValues ) => {
        const params = {
            currentPage: pagination.current,
            pageSize: pagination.pageSize,
            ...formValues,
        };
        this.props.dispatch({
            type: 'orderManage/modShipping',
            payload: {order_id: order_id},
            callback: (response) => {
                if (response.result === 0) {
                    message.success('提交成功');
                    const {dispatch} = this.props;
                    dispatch({
                        type: 'orderManage/fetch',
                        payload:params
                    });
                } else {
                    message.success('提交失败');
                }
            }
        });
    }

    // handleOrderDetail = (record,pagination) =>{
    //     const {dispatch} = this.props;
    //     dispatch({
    //         type: 'orderManage/keepData',
    //         payload: {
    //             ...record,
    //             editType: 'mod',
    //             order_id: record.order_id,
    //         },
    //     });
    //     dispatch(routerRedux.push('/order/orderDetails'));
    //
    // };
    handleOrderListChange = (pagination) => {
        this.props.onChange(pagination);
    }



    render(){
        const {data: {list, pagination}, loading,orderManage,formValues} = this.props;

        const columns = [{
            dataIndex:'order_id',
            title:'订单ID',
            width:'100px'
        },{
            title:'会员',
            dataIndex:'nick_name',
            width:'100px'
        },{
            title:'店铺',
            dataIndex:'shop_name',
            width:'100px'
        },{
        //     title:'配送方式',
        //     dataIndex:'shipping_name',
        // },{
        //     title:'支付方式',
        //     dataIndex:'pay_name',
        // },{
            title:'订单号',
            dataIndex:'order_sn',
            width:'200px'
        },{
            title:'下单时间',
            dataIndex:'add_time',
            width:'200px'
        },
            {
            title:'订单的状态',
            dataIndex:'order_status',
            width:'150px'
        },{
            title:'商品配送情况',
            dataIndex:'shipping_status',
            width:'150px'
        },{
            title:'支付状态',
            dataIndex:'pay_status',
            width:'150px'
        },{
            title:'服务评价',
            dataIndex:'oga_service',
            render:(val,record) =>{
                return (
                <Rate disabled defaultValue={val}/>
                )
            }
        },{
            title:'商品评价',
            dataIndex:'oga_goods',
            render:(val,record) =>{
                return (
                    <Rate disabled defaultValue={val}/>
                )
            }
        },{
            title:'物流评价',
            dataIndex:'oga_shipping',
            render:(val,record) =>{
                return (
                    <Rate disabled defaultValue={val}/>
                )
            }
        },{
        //     title:'已付金额',
        //     dataIndex:'money_paid',
        // },{
        //     title:'使用的积分数量',
        //     dataIndex:'integral',
        // },{
        //     title:'使用积分金额',
        //     dataIndex:'integral_money',
        // },{
        //     title:'使用红包金额',
        //     dataIndex:'bonus',
        // },{
        //     title:'应付款金额',
        //     dataIndex:'order_amount',
        // },{
        //     title:'订单生成时间',
        //     dataIndex:'add_time',
        // },{
        //     title:'订单确认时间',
        //     dataIndex:'confirm_time',
        // },{
        //     title:'订单支付时间',
        //     dataIndex:'pay_time',
        // },{
        //     title:'订单配送时间',
        //     dataIndex:'shipping_time',
        // },{
            title: '操作',
            width:'150px',
            fixed:'right',
            // fixed: 'right',
            render: (val, record) => (
                <p>
                    {/*<a href="javascript:" onClick={() => this.handleUpdateConfirm(record.order_id,pagination,formValues )}>确认订单</a>|*/}
                    {/*<a href="javascript:" onClick={() => this.handleUpdatePay(record.order_id,pagination,formValues)}>确认发货</a>*/}
                    {/*<a href="javascript:" onClick={() => this.handleUpdateShipping(record.order_id,pagination,formValues)}>确认配送</a>|*/}
                    <AuthButton  ghost  className={styles.btn} size="small"  auth="orderManage.detail" ><Link to={{pathname:'/order/orderDetails',state:{record:record}}}>订单操作</Link></AuthButton >
                </p>


            ),
        },];
        const paginationProps={
            showQuickJumper:true,
            showSizeChanger:true,
            ...pagination,
        }
        return (
            <div className={styles.standardTable}>
                <Table
                    loading={loading}
                    columns={columns}
                    size="default"
                    dataSource={list}
                    scroll={{x:1900}}
                    pagination={paginationProps}
                    onChange={this.handleOrderListChange}
                    rowKey={new Date().toLocaleDateString()}/>
            </div>
        )
    }
}
